<?php
//IINDEX FILE
//Handles all the requests to the server. If no paremeters is given, the game page will  load.

//Includes the different clases
if(file_exists('configFiles/mainConf.php')) {
    require_once('configFiles/mainConf.php');
} else {
    die('MainConf file not found!');
}

//Configuraion
   if(isset($_GET['r']) || isset($_POST['r']))  {
    $request = (isset($_REQUEST['r'])) ? $_REQUEST['r'] : false;
    $func = (isset($_REQUEST['f'])) ? $_REQUEST['f'] : false;
    $parm =  (isset($_REQUEST['p'])) ? $_REQUEST['p'] : false;
   } else {
       $request = false;
   }
    
    switch($request) {
        //Get a new map
        case "xmap":
            if($func) {                
                //Creates a new XMAP PHP Object, load and creates the map
                $xmap = new XMap('configfiles/xmapConfig.xml');
                $ret = call_user_func(array($xmap, $func), $parm);
                
                if($ret != null && headers_sent() != true) {
                    header("Content-type: application/json");
                    echo json_encode($ret);
                }
                
            } else {
                err('No Value given!!!');
            }
        break;
        
        case "javaConf":
            header("Content-type: application/json");
            echo json_encode($gameJSOpt);
            break;
        default:
            $GS = new GoldenShield($goldenConfig);
            $GS->loadGame();
            break;
    }
    
//Error function, displays an error
function err($msg) {
    die('<b>Ajax.php error:</b> '. $msg);
}
?>